use serde::{Deserialize, Serialize};
use serde_json::json;

#[derive(Serialize, Deserialize, Debug)]
struct Person {
    name: String,
    age: u8,
    phones: Vec<String>,
}

pub fn demo() {
    // 创建一个Person对象
    let person = Person {
        name: String::from("John"),
        age: 30,
        phones: vec![String::from("123456789"), String::from("987654321")],
    };

    // 将Person对象序列化为JSON字符串
    let serialized = serde_json::to_string(&person).unwrap();
    println!("Serialized: {}", serialized);

    // 将JSON字符串反序列化为Person对象
    let deserialized: Person = serde_json::from_str(&serialized).unwrap();
    println!("Deserialized: {:?}", deserialized);

    let p1 = json!({"name":"John","age":30,"phones":["123456789","987654321"]});
    println!("json! {}", p1);

    let p2 = p1.to_string();
    println!("p1 json {}", p2);

    let p3: Person = serde_json::from_str(&p2).unwrap();
    println!("p3! {:#?}", p3);
}
